package com.hzit.servlet;


import com.alibaba.fastjson.JSON;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.hzit.common.utils.R;
import com.hzit.entity.Student;
import com.hzit.service.ClassesService;
import com.hzit.service.impl.ClassesServiceImpl;
import com.hzit.entity.Classes;

import javax.servlet.ServletException;
import javax.servlet.ServletInputStream;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
 * 类名：
 * 作者：WF
 * 功能：
 */
@WebServlet("/classes")
public class ClassesServlet extends HttpServlet {
	private ClassesService classesService;

	@Override
	public void init() throws ServletException {
		classesService = new ClassesServiceImpl();
	}

	@Override
	protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		resp.setContentType("application/json;charset=utf-8");
		List<Classes> classes = classesService.findAll();
		R r = R.ok().data("list", classes);
		resp.getWriter().println(JSON.toJSONString(r));
		ObjectMapper mapper = new ObjectMapper();
		ServletInputStream is = req.getInputStream();


		resp.getWriter().flush();
	}
}
